var num = 5;
var popdom = `<div class="popwindow" onclick="removes(this)">
        <div class="pop-ur">
            <img src="../../img/popullarize/p2.png"/>
        </div>
        <div class="popbot flexs-center">
            <div class="pop-l">
                <img src="../../img/popullarize/s.png"/>
                <p>发送好友</p>
            </div>
        </div>
        <div class="toasttext">
            戳这里，分享给好友！
        </div>
    </div>`;
var shareInfo;
var s;
var Handle = {
    init:function(){
        $("body").append(popdom);
        s = new wxee();
        s.signature();
        this.getData();

    },
    eventLisenter:function(){
        $(".intenthtml").click(function(){
            window.location.href=$(this).attr("href");
        });
        $(".btn-hand").click(function(){
            $(".enternum input").val(num);
            num>0 ? $(".btn-submit div").removeClass("disable"):$(".btn-submit div").hasClass("disable")?null:$(".btn-submit div").addClass("disable");
        });
		$('input').bind('input propertychange', function() { 
		　　//console.log();
			if($(this).val()>num){
				$(this).val(num);
			}
			$(this).val()>0 ? $(".btn-submit div").removeClass("disable"):$(".btn-submit div").hasClass("disable")?null:$(".btn-submit div").addClass("disable");
		});
		var _that=this;
        $(".btn-submit div").click(function(){
            _that.getGuobiShareInfo();

        });

    },
    getData:function(){
        new AjaxRequest({
            type: "get",
            url:apiService.getMyGuobiCount,
            param: "",
            callBack:function(res){
				num = res.payload;
				$(".handnum a").text(num);
            },
            failBack: function(){
                // $(".handnum a").text(num);
            }
        });
    },
    sendG:function(data){
        alert($('input').val());
        new AjaxRequest({
            type: "get",
            url:apiService.sendGuobi+"?sendCnt="+$('input').val(),
            param:"",
            callBack:function(res){
                alert(res.message);
            },
            failBack: function(){
            }
        });
    },
    getGuobiShareInfo:function(){
        new AjaxRequest({
            type: "get",
            url:apiService.getGuobiShareInfo+"?sendCnt="+$('input').val(),
            param: "",
            callBack:function(res){
                shareInfo = res;
                var shareData = {
                    title: shareInfo.payload.title,
                    desc: shareInfo.payload.desc,
                    link: shareInfo.payload.link,
                    imgUrl: shareInfo.payload.imgUrl,
                    callback:function(){
                        $(".popwindow").remove();
                        // Handle.sendG(null);
                    }
                }

                alert(res.code);
                s.setData(shareData);
            },
            failBack: function(){
            }
        });
    }
}

function oncilk(dom){
    window.location.href=$(dom).attr("href");
}
function removes(dom){
    $(dom).remove();
}
function buildDom(data,id){
    var dom = `<div class="jl-item flexs-pace-between">
                <div class="flexs-center tg-i-l">
                    <img src=""/>
                    <div class="tg-tixt" style="margin-left:0.5rem">
                        <p style="font-weight: bold">推广时间 : 2018-08-12 15:01</p>
                        <p style="font-weight: bold">会话对象 : 小狐狸</p>
                        <p>访问次数 : 123</p>
                        <p>访问用户 : 12</p>
                    </div>
                </div>
                <div class="flexs-pace-between-col tg-i-r">
                    <p class="sharetype">微信会话分享</p>
                    <p class="money">+18.00元</p>
                </div>
            </div>`;
    $(id).append(dom);
}